//
//  LoadDetailsCerTableViewCell.m
//  CreditHub
//
//  Created by chenglang on 2024/9/18.
//

#import "LoadDetailsCerTableViewCell.h"
#import "LoadDetailsCerItemCell.h"
@interface LoadDetailsCerTableViewCell ()
@property (nonatomic, strong) NSArray *soundedList;
@end
@implementation LoadDetailsCerTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code

    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"LoadDetailsCerItemCell" bundle:nil] forCellReuseIdentifier:@"LoadDetailsCerItemCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"LoanMterialsTitleCell" bundle:nil] forCellReuseIdentifier:@"LoanMterialsTitleCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"LoanMterialsStepCell" bundle:nil] forCellReuseIdentifier:@"LoanMterialsStepCell"];
    self.tableView.estimatedRowHeight = 44;
}



- (void)showList:(NSArray *)array block:(DidSelectRowBlock)block{
    _soundedList = array;
    [self.tableView reloadData];
    self.layoutHeight.constant = 85*array.count;
    self.selectBlock = block;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.soundedList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LoadDetailsCerItemCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LoadDetailsCerItemCell"];
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:self.soundedList[indexPath.row]];
    cell.labelTitle.text = CHString(dic[@"outside"]);
    [[ImageLoader sharedInstance] loadImageFromURL:[NSURL URLWithString:CHString(dic[@"boxedtinker"])] imageView:cell.imgViewIcon completion:^(UIImage * _Nonnull image, NSError * _Nonnull error) {
        
    }];
    cell.buttonCer.selected = [dic[@"camping"] boolValue];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    return 85;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:self.soundedList[indexPath.row]];
//    NSLog(@"-%@----self.nextDicInfo--------%@",dic[@"till"],self.nextDicInfo);
    self.selectBlock(dic);
    
}

@end
